package com.sense.kukoo.biz_media.model

import com.sense.kukoo.common.mvvm.model.BaseMvvmModel
import com.sense.kukoo.common.repo.bean.ResultBean
import com.sense.kukoo.common.repo.http.KukooHttpApi
import com.sense.kukoo.common.repo.http.KukooHttpManager
import com.sense.kukoo.common.repo.http.bean.ContentInfoBean
import com.sense.kukoo.common.repo.http.bean.ListenRecordBean
import okhttp3.RequestBody

class MediaHistoryModel: BaseMvvmModel() {

    private val TAG: String = javaClass.simpleName

    override fun onModelCleared() {}

    suspend fun listenPage(
        pageIndex: Int,
        pageSize: Int,
    ): ResultBean<List<ListenRecordBean>> {

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .listenPage("${pageIndex}", "${pageSize}")
    }

    suspend fun contentInfo(id: Long): ResultBean<ContentInfoBean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .contentInfo("${id}")
    }

    suspend fun listenDelete(ids: Array<Long>): ResultBean<Boolean> {
        val hashMap = HashMap<String, Any>()
        hashMap.put("ids", ids)
        val mRequestBody: RequestBody = KukooHttpManager.createRequestBody(hashMap)

        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .listenDelete(mRequestBody)
    }

    suspend fun listenClean(): ResultBean<Boolean> {
        return KukooHttpManager.instance
            .createHttpClient(KukooHttpApi::class.java)
            .listenClean()
    }
}